
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/10/2011 01:44:30
-- Generated from EDMX file: C:\Users\Desde\Desktop\my-server-based-feed-aggregator\Server\Server\Server\App_Data\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [mabase];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserUserFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserFeedJeu] DROP CONSTRAINT [FK_UserUserFeed];
GO
IF OBJECT_ID(N'[dbo].[FK_UserFeedFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserFeedJeu] DROP CONSTRAINT [FK_UserFeedFeed];
GO
IF OBJECT_ID(N'[dbo].[FK_DatasExchangedFeed]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DatasExchangedJeu] DROP CONSTRAINT [FK_DatasExchangedFeed];
GO
IF OBJECT_ID(N'[dbo].[FK_UserDatasExchanged]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DatasExchangedJeu] DROP CONSTRAINT [FK_UserDatasExchanged];
GO
IF OBJECT_ID(N'[dbo].[FK_UserDatasExchanged1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DatasExchangedJeu] DROP CONSTRAINT [FK_UserDatasExchanged1];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserJeu];
GO
IF OBJECT_ID(N'[dbo].[FeedJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FeedJeu];
GO
IF OBJECT_ID(N'[dbo].[UserFeedJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserFeedJeu];
GO
IF OBJECT_ID(N'[dbo].[DatasExchangedJeu]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DatasExchangedJeu];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserJeu'
CREATE TABLE [dbo].[UserJeu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Question] nvarchar(max)  NULL,
    [Answer] nvarchar(max)  NULL
);
GO

-- Creating table 'FeedJeu'
CREATE TABLE [dbo].[FeedJeu] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Link] nvarchar(max)  NOT NULL,
    [PubDate] nvarchar(max)  NOT NULL,
    [LastBuildDate] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL,
    [Username] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserFeedJeu'
CREATE TABLE [dbo].[UserFeedJeu] (
    [ID] int  NOT NULL,
    [User_ID] int  NOT NULL,
    [Feed_ID] int  NOT NULL
);
GO

-- Creating table 'DatasExchangedJeu'
CREATE TABLE [dbo].[DatasExchangedJeu] (
    [ID] int  NOT NULL,
    [Feed_ID] int  NOT NULL,
    [UserSender_ID] int  NOT NULL,
    [UserReceiver_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'UserJeu'
ALTER TABLE [dbo].[UserJeu]
ADD CONSTRAINT [PK_UserJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'FeedJeu'
ALTER TABLE [dbo].[FeedJeu]
ADD CONSTRAINT [PK_FeedJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'UserFeedJeu'
ALTER TABLE [dbo].[UserFeedJeu]
ADD CONSTRAINT [PK_UserFeedJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DatasExchangedJeu'
ALTER TABLE [dbo].[DatasExchangedJeu]
ADD CONSTRAINT [PK_DatasExchangedJeu]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [User_ID] in table 'UserFeedJeu'
ALTER TABLE [dbo].[UserFeedJeu]
ADD CONSTRAINT [FK_UserUserFeed]
    FOREIGN KEY ([User_ID])
    REFERENCES [dbo].[UserJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserFeed'
CREATE INDEX [IX_FK_UserUserFeed]
ON [dbo].[UserFeedJeu]
    ([User_ID]);
GO

-- Creating foreign key on [Feed_ID] in table 'UserFeedJeu'
ALTER TABLE [dbo].[UserFeedJeu]
ADD CONSTRAINT [FK_UserFeedFeed]
    FOREIGN KEY ([Feed_ID])
    REFERENCES [dbo].[FeedJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserFeedFeed'
CREATE INDEX [IX_FK_UserFeedFeed]
ON [dbo].[UserFeedJeu]
    ([Feed_ID]);
GO

-- Creating foreign key on [Feed_ID] in table 'DatasExchangedJeu'
ALTER TABLE [dbo].[DatasExchangedJeu]
ADD CONSTRAINT [FK_DatasExchangedFeed]
    FOREIGN KEY ([Feed_ID])
    REFERENCES [dbo].[FeedJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DatasExchangedFeed'
CREATE INDEX [IX_FK_DatasExchangedFeed]
ON [dbo].[DatasExchangedJeu]
    ([Feed_ID]);
GO

-- Creating foreign key on [UserSender_ID] in table 'DatasExchangedJeu'
ALTER TABLE [dbo].[DatasExchangedJeu]
ADD CONSTRAINT [FK_UserDatasExchanged]
    FOREIGN KEY ([UserSender_ID])
    REFERENCES [dbo].[UserJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserDatasExchanged'
CREATE INDEX [IX_FK_UserDatasExchanged]
ON [dbo].[DatasExchangedJeu]
    ([UserSender_ID]);
GO

-- Creating foreign key on [UserReceiver_ID] in table 'DatasExchangedJeu'
ALTER TABLE [dbo].[DatasExchangedJeu]
ADD CONSTRAINT [FK_UserDatasExchanged1]
    FOREIGN KEY ([UserReceiver_ID])
    REFERENCES [dbo].[UserJeu]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserDatasExchanged1'
CREATE INDEX [IX_FK_UserDatasExchanged1]
ON [dbo].[DatasExchangedJeu]
    ([UserReceiver_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------